package com.crayon.account;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;

import com.crayon.account.dao.DAOFood;
import com.crayon.account.dao.DAOPhotos;
import com.crayon.account.fragments.FragmentRGWrite;
import com.crayon.account.fragments.FragmentWriteFood;
import com.crayon.sharemenu.R;
import com.crayon.util.ActivityCameraCrop;
import com.crayon.util.GDB;
import com.crayon.util.UIBIND;

public class ActivityComposeMenu extends FragmentActivity
		implements FragmentWriteFood.OnFoodAppendAction{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		if(getActionBar()!=null)getActionBar().hide();
		setContentView(R.layout.activity_compose);
		FragmentWriteFood fragment= FragmentWriteFood.onCreateInstance(getIntent().getExtras());
		fragment.setOnFoodAppendAction(this);
		FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
		ft.replace(R.id.item_container, fragment);
		ft.commit();

	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		GDB.log(getClass(), ">>>>@onActivityResult REQUESTCODE_CAMERA " + ActivityCameraCrop.REQUESTCODE_CAMERA);
		GDB.log(getClass(), ">>>>@onActivityResult " + requestCode);
		GDB.log(getClass(), ">>>>@onActivityResult " + resultCode);
		GDB.log(getClass(), ">>>>@onActivityResult " + data);

		if(data!=null){
			DAOPhotos daophoto = (DAOPhotos)data.getSerializableExtra("daophoto");
//			tbFood.setUri(daophoto.getUri());
//			byte[] imgarr = data.getByteArrayExtra("data");
//			if(imgarr!=null &&imgarr.length>0){
//				try {
//					UIBIND.bindImageViewBitmapArray(getView(), R.id.photoImageView, imgarr);
//					UIBIND.bindViewVisible(getView(), R.id.buttonImageDelete, true);
//				} catch (Exception e) {
//					// TODO: handle exception
//				}
//			}
		}

		super.onActivityResult(requestCode, resultCode, data);
	}

	@Override
	public void OnActionCallCamera(DAOFood food) {
		Intent intent= new Intent(this,ActivityCameraCrop.class);
		intent.putExtra(ActivityCameraCrop.PARAM_UUID, food.getUuid());
		startActivityForResult(intent, 0x00);

	}
}
